package com.longcai.cm.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author LBX
 */
@Data
@ApiModel(description = "统一返回结果")
public class R<T> {

//	private static final long serialVersionUID = 1L;

    @ApiModelProperty(required = true, notes = "返回状态码(0标识成功  其他标识失败，取msg)", example = "0")
    private int code;

    @ApiModelProperty(required = true, notes = "响应时间", example = "15670000552")
    private long time = System.currentTimeMillis();

    @ApiModelProperty(required = true, notes = "返回提示", example = "返回成功")
    private String msg;

    @ApiModelProperty(required = true, notes = "返回数据")
    private T data;


    public R() {
        super();
    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> R<T> success() {
        return new R<>(0, "操作成功", null);
    }

    public static <T> R<T> success(T data) {
        return new R<>(0, "操作成功", data);
    }


    public static <T> R<T> error() {
        return new R<>(500, "操作失敗", null);
    }

    public static <T> R<T> error(String msg) {
        return new R<>(500, msg, null);
    }

    public static <T> R<T> error(int code, String msg) {
        return new R<>(code, msg, null);
    }

}
